package com.linewow.xhyy.nihaonew.application;

import android.app.ActivityManager;
import android.content.Context;
import android.support.multidex.MultiDexApplication;
import android.util.Log;

import com.linewow.xhyy.hrxb.DemoHelper;
import com.linewow.xhyy.nihaonew.db.NiHaoHelper;

import org.lasque.tusdk.core.TuSdk;

import cn.jpush.android.api.JPushInterface;


/**
 * Created by LXR on 2016/9/19.
 */
public class NiHaoApp extends MultiDexApplication {
    public static boolean flag;
    public static String token;
    public static String uid;
    public static String nick;
    private NiHaoHelper niHaoHelper;
    private static NiHaoApp instance;
    public static boolean EnglishFlag;
    @Override
    public void onCreate() {
        super.onCreate();
        String processName=getCurProcessName(NiHaoApp.this);
        if(processName.equals("com.linewow.xhyy.nihaonew")){
            instance=this;
            niHaoHelper=NiHaoHelper.getInstance();
            niHaoHelper.init(getApplicationContext());
            JPushInterface.init(instance.getApplicationContext());
            JPushInterface.setDebugMode(true);

            resumeData();
            initHrXbData();
            initUmeng();
            TuSdk.init(this.getApplicationContext(),"5aae849ad79c43dc-00-tyqbq1");
            Log.e("tusdk","tusdk初始化开始了");
        }
        Log.e("NiHaoApp","启动了"+processName);
    }

    private void initUmeng() {
//        UMShareAPI.get(NiHaoApp.this);
//        PlatformConfig.setWeixin("wx7d57b98372709bcf", "bc532cb22b9799921f36b65e83913301");
//        PlatformConfig.setSinaWeibo("3864203031", "d28ff5c9093d6f8abc22ef9ea4f112c7");
//        PlatformConfig.setQQZone("1105728333", "jsc8oB0mfoyMGgjc");
//        Config.REDIRECT_URL="http://www.neahow.com/";
//        MobclickAgent.openActivityDurationTrack(false);
    }

    private void initHrXbData() {
//        EMOptions options=new EMOptions();
//        options.setAcceptInvitationAlways(false);
//        EMClient.getInstance().init(NiHaoApp.this,options);
//        EMClient.getInstance().setDebugMode(false);
        DemoHelper.getInstance().init(NiHaoApp.this);
    }

    public void resumeData(){
        flag=niHaoHelper.getToken();
        token=niHaoHelper.getTokenContent();
        uid=niHaoHelper.getUidContent();
    }

    public static NiHaoApp getInstance(){
        return  instance;
    }

    private String getCurProcessName(Context context) {
        int pid = android.os.Process.myPid();
        ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningAppProcessInfo appProcess : activityManager.getRunningAppProcesses()) {
            if (appProcess.pid == pid) {
                return appProcess.processName;
            }
        }
        return "";
    }
}
